package com.gzx.spring.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter(); 
    }
    
    /**
     *  风控：消息队列
     */
    @Bean("risk-str")
    public Queue riskQueueStr() {
        return new Queue("risk-str");
    }

    
    /**
     *  风控：消息队列
     */
    @Bean("risk-str-self")
    public Queue riskQueueStrSelf() {
        return new Queue("risk-str-self");
    }

    
    /**
     * 风控：交换器
     */
    @Bean("risk")
    public DirectExchange riskExchange() {
        return new DirectExchange("risk");
    }

    /**
     * 绑定
     */
    @Bean
    public Binding riskQueueStrBinding(@Qualifier("risk-str") Queue queue,
                                              @Qualifier("risk") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("risk-str");
    }
    
    /**
     * 绑定
     */
    @Bean
    public Binding riskQueueStrTestBinding(@Qualifier("risk-str-self") Queue queue,
                                              @Qualifier("risk") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("risk-str");
    }

}